﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MySql.Data.MySqlClient;
using MySql.Data;
using BE;
using System.Data;
using Mapeo;
using NHibernate;

namespace DAL
{
    public class Data_Obs_Prueba_DAL: Controlador
    {
        public void Insertar (Data_Obs_Prueba_BE obj) 
        {
            using (ISession Sesion = m_SessionFactory.OpenSession())
            {
                using (ITransaction Trans = Sesion.BeginTransaction())
                {
                    MySqlCommand SqlCmd = new MySqlCommand();
                    SqlCmd.Connection = (MySqlConnection)Sesion.Connection;
                    Trans.Enlist(SqlCmd);
                    SqlCmd.CommandText = "sp_DATA_Observacion_Inserta";
                    SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlCmd.Parameters.AddWithValue("@in_semestre", obj.semestre);
                    SqlCmd.Parameters.AddWithValue("@in_cod_alumno", obj.codAlumno);
                    SqlCmd.Parameters.AddWithValue("@in_condicion", obj.condicion);
                    SqlCmd.Parameters.AddWithValue("@in_estado", obj.estado);
                    SqlCmd.Parameters.AddWithValue("@in_descrip", obj.descrip);
                    SqlCmd.Parameters.AddWithValue("@in_observac", obj.observac);
                    SqlCmd.Parameters.AddWithValue("@in_ciclo", obj.ciclo);
                    SqlCmd.Parameters.AddWithValue("@in_actaoera", obj.actaoera);
                    SqlCmd.Parameters.AddWithValue("@in_id_obs", obj.id_obs);
                    SqlCmd.Parameters.AddWithValue("@in_cursos", obj.cursos);
                    SqlCmd.Parameters.AddWithValue("@in_cod_curso", obj.codCurso);
                    SqlCmd.Parameters.AddWithValue("@in_toma_curso", obj.toma_curso);
                    SqlCmd.ExecuteNonQuery();
                    Trans.Commit();
                }
            }     
        }

        public void Actualizar(Data_Obs_Prueba_BE obj)
        {
            using (ISession Sesion = m_SessionFactory.OpenSession())
            {
                using (ITransaction Trans = Sesion.BeginTransaction())
                {
                    MySqlCommand SqlCmd = new MySqlCommand();
                    SqlCmd.Connection = (MySqlConnection)Sesion.Connection;
                    Trans.Enlist(SqlCmd);
                    SqlCmd.CommandText = "sp_DATA_Observacion_Actualiza";
                    SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlCmd.Parameters.AddWithValue("@in_semestre", obj.semestre);
                    SqlCmd.Parameters.AddWithValue("@in_cod_alumno", obj.codAlumno);
                    SqlCmd.Parameters.AddWithValue("@in_condicion", obj.condicion);
                    SqlCmd.Parameters.AddWithValue("@in_estado", obj.estado);
                    SqlCmd.Parameters.AddWithValue("@in_observac", obj.observac);
                    SqlCmd.Parameters.AddWithValue("@in_cursos", obj.cursos);
                    SqlCmd.Parameters.AddWithValue("@in_cod_curso", obj.codCurso);
                    SqlCmd.Parameters.AddWithValue("@in_toma_curso", obj.toma_curso);
                    SqlCmd.ExecuteNonQuery();
                    Trans.Commit();
                }
            }
        }

        public void Eliminar(Data_Obs_Prueba_BE obj)
        {
            using (ISession Sesion = m_SessionFactory.OpenSession())
            {
                using (ITransaction Trans = Sesion.BeginTransaction())
                {
                    MySqlCommand SqlCmd = new MySqlCommand();
                    SqlCmd.Connection = (MySqlConnection)Sesion.Connection;
                    Trans.Enlist(SqlCmd);
                    SqlCmd.CommandText = "sp_DATA_Observacion_Elimina";
                    SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlCmd.Parameters.AddWithValue("@in_semestre", obj.semestre);
                    SqlCmd.Parameters.AddWithValue("@in_cod_alumno", obj.codAlumno);   

                    SqlCmd.ExecuteNonQuery();
                    Trans.Commit();
                }
            }
        }
    }
}
